<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>excel文件上传</title>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function test1(){
  if($("#uploadFile").val().trim()===""){
    alert("上传文件不能为空");
    return;
  };
    var form = new FormData(document.getElementById("uploadForm"));  
  $.ajax({
      url:"./ExcelServlet",
      type:"post",
      async:false,
      data:form,
      dataType:"text",
      processData: false,  // 告诉jQuery不要去处理发送的数据
      contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
      success:function(result){
 
        if(result==="success"){
          alert("上传成功");
        }else{
          alert("上传失败");
        }
      },
      error:function(){
        alert("servlet执行返回值出错");
      }
  }); 
 
}
 
 
</script>
 
</head>
<body>
<h1>excel文件上传至数据库测试页面</h1>
<form id="uploadForm" method="post" action="" enctype="multipart/form-data">
    选择一个文件:
    <input id="uploadFile" type="file" name="uploadFile" />
    <br/><br/>
    <input type="button" value="上传" onclick="test1()" />
</form>
 
 
</body>
</html>